package com.baizhi.service.impl;

import com.baizhi.annolation.LogAnnotation;
import com.baizhi.dao.BannerDao;
import com.baizhi.entity.Banner;
import com.baizhi.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service

@Transactional
public class BannerServiceImpl implements BannerService {
   @Autowired
    private BannerDao bannerDao;
    @Override
    @LogAnnotation(type = "轮播图模块",value="查询了所有的轮播图信息")
    public Map selectAll(Integer page, Integer limit) {
        Map map=new HashMap();
        int offset=(page-1)*limit;

        //分页查询
        List<Banner> banners = bannerDao.selectAll(offset, limit);
        int i = bannerDao.countBanner();
        //响应ma集合
        map.put("data",banners);
        map.put("msg","");
        map.put("code",0);
        map.put("count",i);
        return map;

    }

    @Override
    @LogAnnotation(type = "轮播图模块",value="隐藏了轮播图信息")
    public void deleteBanner(Integer id) {
        bannerDao.deleteBanner(id);

    }

    @Override
    @LogAnnotation(type = "轮播图模块",value="添加轮播图信息")

    public void insertBanner(Banner banner) {
        bannerDao.insertBanner(banner);
    }

    @Override
    @LogAnnotation(type = "轮播图模块",value="修改轮播图信息")
    public void updateBanner(Banner banner) {
        bannerDao.updateBanner(banner);
    }

    @Override
    @LogAnnotation(type = "轮播图模块",value="改变了轮播图状态为显示或者隐藏")
    public void updateBannerStatus(Integer status, Integer id) {
        //如果显示则变为隐藏状态
        if(status==0){
            bannerDao.updateHiddenStatus(id);
            //如果隐藏则变为显示状态
        }else if (status==2){
            bannerDao.updateShowStatus(id);
        }
    }
}
